package com.xmu.prcs.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;
/**
 * 主题表
 * @author frequent
 *
 */
@SuppressWarnings("serial")
@Entity
@Table(name = "topic", uniqueConstraints = @UniqueConstraint(columnNames = "topicname"))
public class Topic implements Serializable {

	private Integer idTopic;
	private String topicName;//主题名
	private Integer postNumber;//帖子数
	private String note;//主题介绍
	private Date updateTime;//更新时间
	private Set<Post> posts;//主题下的所有帖子
	private Set<User> chargePersons;//版主
	
	public Topic(){
		
	}
	
	public Topic(String topicName, Integer postNumber, String note){
		this.topicName = topicName;
		this.postNumber = postNumber;
		this.note = note;
	}

	@Id
	@GeneratedValue
	@Column(name = "idtopic", unique = true, nullable = true)
	public Integer getIdTopic() {
		return idTopic;
	}

	public void setIdTopic(Integer idTopic) {
		this.idTopic = idTopic;
	}

	@Column(name = "topicname", length = 20)
	public String getTopicName() {
		return topicName;
	}

	public void setTopicName(String topicName) {
		this.topicName = topicName;
	}

	@Column(name = "postnumber")
	public Integer getPostNumber() {
		return postNumber;
	}

	public void setPostNumber(Integer postNumber) {
		this.postNumber = postNumber;
	}

	@Column(name = "note", length = 200)
	public String getNote() {
		return note;
	}

	public void setNote(String note) {
		this.note = note;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
	@JoinColumn(name = "idtopic")
	public Set<Post> getPosts() {
		return posts;
	}

	public void setPosts(Set<Post> posts) {
		this.posts = posts;
	}

	@Column(name = "updatetime")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "topic_chargeperson",
			joinColumns = {@JoinColumn(name = "idtopic")},
			inverseJoinColumns = {@JoinColumn(name = "iduser")})
	public Set<User> getChargePersons() {
		return chargePersons;
	}

	public void setChargePersons(Set<User> chargePersons) {
		this.chargePersons = chargePersons;
	}
	
}
